package com.xiaolun.layui.controller;

import com.xiaolun.layui.mapper.ProductMapper;
import com.xiaolun.layui.service.ProductService;
import com.xiaolun.layui.vo.BarVO;
import com.xiaolun.layui.vo.DataVO;
import com.xiaolun.layui.vo.ProductBarVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ProductController {

	@Autowired
	private ProductService productService;
	@Autowired
	private ProductMapper productMapper;

	/**
	 * 返回json数据 http://localhost:8080/list?page=2&limit=10
	 * 针对的文件是：src/main/resources/templates/table.html
	 * @param page
	 * @param limit
	 * @return
	 */
	@RequestMapping("/list")
	@ResponseBody
	public DataVO list(Integer page, Integer limit) {
		return productService.findData(page, limit);
	}

	@GetMapping("/{url}") //http://localhost:8080/table 和上面请求同
	public String redirect(@PathVariable("url") String url) {
		return url;
	}

	@RequestMapping("/barVO")
	@ResponseBody
	public BarVO getBarVO() {
		return productService.getBarVO();
	}

	// 通过PieVO实体进行访问
//    @RequestMapping("/pieVO")
//    @ResponseBody
//    public List<PieVO> getPieVO(){
//        return productService.getPieVO();
//    }

	// 通过ProductBarVO实体进行访问，和上面的PieVO实体访问作用同
	@RequestMapping("/pieVO")
	@ResponseBody
	public List<ProductBarVO> getPieVO() {
		return productMapper.findAllProductBarVO();
	}

}
